/**
 * @author chili
 * @date 2019-06-05
 * @description: 消息推送
 */

//消息类型集合
let receivePoliceObj = [101, 102, 103, 104, 105, 106, 107]; //接处警
let highRiskObj = [201, 202, 203]; //高危信号
let majorIssuesObj = [301, 302, 303]; //重大问题
let chagangObj = [401, 402, 403]; //查岗
let clockObj = [501]; //打卡
let signObj = [601]; //签到
let inspectObj = [701, 702, 703, 704]; //巡检
let hiddenDangersObj = [801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816]; //隐患整改
let maintenceInspectObj = [901, 902, 903, 904, 905, 906, 907, 908]; //维保巡查
let maintenceObj = [1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009]; //保养
let singleTestObj = [1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109]; //单点测试
let linkTestObj = [1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208]; //联动测试
let testObj = [1301, 1302]; //测试
let temporaryTasksObj = [1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409]; //临时任务
let applyForWorkObj = [1501, 1502, 1503, 1504, 1505, 1506]; //作业申请
let emergencyObj = [1601, 1602]; //应急救援
let otherMsgObj = [9901, 9902, 9903, 9904, 9905, 9908, 9909]; //其它消息
let bsVedioCall = [9906]; //大屏视频通话功能
let kaoShi = [9907];
let changeShift = [10001]; //交接班
let policeClose = [1701, 1702] //警情关闭推送
var push = (function (_self) {

  //获取推送消息
  _self.getPush = function (oContent, oContext, type) { //type==true为手动触发消息弹窗
    if (_self.isLoadSys()) {
      if (native.getDataByKey("OFFLINE_SELECT_FLAG") != 1) { //离线维保不允许推送
        if (oContent && oContext) {
          //关闭所有弹窗
          app.popup.close();
          app.popover.close();
          let content = JSON.parse(oContent);
          let context = JSON.parse(oContext);
          // let content = {  "isUnit" : 0,  "messageTypeName" : "报警",  "messageTypeIcon" : "https:\/\/img.kdlayun.com\/dic\/rdspFile_1539675998374.png",  "organizationId" : 142,  "roleIds" : "142,144,145,185",  "description" : "周口师范学院过道001回路001号烟感报警",  "messageType" : 1506,  "createTime" : "2019-06-14 16:08:56"}
          // let context = {"organizationId":142,"handlerStatus":-1,"fireTTypes":"10","organizationName":"周口师范学院","createTime":"2019-06-14 16:08:56","selfDesc":"过道001回路001号烟感报警","businessId":41152210,"fcFacilitiesId":2158910,"isReset":0};
          let pushType = content.messageType; //消息推送类型
          if (pushType == 10001) {
            type = true
          }
          //接处警
          if (jQuery.inArray(pushType, receivePoliceObj) > -1) {
            if (type) {
              _self.dealPushForJieChuJing(pushType, content, context);
            }
          }
          //高危信号
          else if (jQuery.inArray(pushType, highRiskObj) > -1) {
            if (type) {
              _self.dealPushForGaoWeiXinHao(pushType, content, context);
            }
          }
          //重大问题
          else if (jQuery.inArray(pushType, majorIssuesObj) > -1) {
            if (type) {
              _self.dealPushForZhongdaWenTi(pushType, content, context);
            }
          }
          //查岗
          else if (jQuery.inArray(pushType, chagangObj) > -1) {
            if (type) {
              _self.dealPushForChaGang(pushType, content, context);
            }
          }
          //打卡
          else if (jQuery.inArray(pushType, clockObj) > -1) {
            if (type) {
              _self.dealPushForDaKa(pushType, content, context);
            }
          }
          //签到
          else if (jQuery.inArray(pushType, signObj) > -1) {
            if (type) {
              _self.dealPushForQianDao(pushType, content, context);
            }
          }
          //巡检
          else if (jQuery.inArray(pushType, inspectObj) > -1) {
            if (type) {
              _self.dealPushForXunJian(pushType, content, context);
            }
          }
          //隐患整改
          else if (jQuery.inArray(pushType, hiddenDangersObj) > -1) {
            if (type) {
              _self.dealPushForYinHuanZhengGai(pushType, content, context);
            }
          }
          //维保巡查
          else if (jQuery.inArray(pushType, maintenceInspectObj) > -1) {
            if (type) {
              _self.dealPushForWeiBaoXUnCha(pushType, content, context);
            }
          }
          //保养
          else if (jQuery.inArray(pushType, maintenceObj) > -1) {
            if (type) {
              _self.dealPushForBaoYang(pushType, content, context);
            }
          }
          //考试
          else if (jQuery.inArray(pushType, kaoShi) > -1) {
            if (type) {
              _self.dealPushForKaoShi(pushType, content, context);
            }
          }
          //警情关闭
          else if (jQuery.inArray(pushType, policeClose) > -1) {
            if (type) {
              _self.dealPushForPoliceClose(pushType, content, context);
            }
          }
          //单点测试
          else if (jQuery.inArray(pushType, singleTestObj) > -1) {
            if (type) {
              _self.dealPushForDanDianCeShi(pushType, content, context);
            }
          }
          //联动测试
          else if (jQuery.inArray(pushType, linkTestObj) > -1) {
            if (type) {
              _self.dealPushForLianDongCeShi(pushType, content, context);
            }
          }
          //测试
          else if (jQuery.inArray(pushType, testObj) > -1) {
            if (type) {
              _self.dealPushForCeShi(pushType, content, context);
            }
          }
          //临时任务
          else if (jQuery.inArray(pushType, temporaryTasksObj) > -1) {
            if (type) {
              _self.dealPushForLinShiRenWu(pushType, content, context);
            }
          }
          //作业申请
          else if (jQuery.inArray(pushType, applyForWorkObj) > -1) {
            if (type) {
              _self.dealPushForZuoYeShenQing(pushType, content, context);
            }
          }
          //应急救援
          else if (jQuery.inArray(pushType, emergencyObj) > -1) {
            if (type) {
              _self.dealPushForYingJiJiuYuan(pushType, content, context);
            }
          }
          //其它消息
          else if (jQuery.inArray(pushType, otherMsgObj) > -1) {
            if (type) {
              _self.dealPushForOther(pushType, content, context);
            }
          }
          //交接班
          else if (jQuery.inArray(pushType, changeShift) > -1) {
            if (type) {
              _self.dealPushForChangeShift(pushType, content, context);
            }
          }
          //大屏视频通话
          else if (jQuery.inArray(pushType, bsVedioCall) > -1) {
            if (type) {
              //APP在打开音视频对讲
              Dao.getAliRTCToken({
                channelID: context.channelID, //Y	String	房间号
                user: userInfor.accountName //Y	String	当前用户
              }, function (result) {
                if (result) {
                  result.myName = userInfor.name
                  result.channelID = context.channelID
                  native.openBsVedioCall(result);
                }
              });
            }
          } else {
            app.methods.showToastCenter("推送消息有误");
          }
        } else {
          app.methods.showToastCenter("未接受到推送消息内容");
        }
      }
    }
  }

  _self.setRead = function (content, context) {
    //拿消息记录id
    Dao.getPushMessageId({
      pushTime: content.createTime,
      pushType: content.messageType,
      content: JSON.stringify(context),
    }, function (data) {
      if (data) {
        //标记为已读
        Dao.operateMessage({
          ids: data, //消息id
          type: 2 //标记为已读
        }, function () {
          native.receiveMessageTab();
        });
      }
    });
  }

  //接处警
  _self.dealPushForJieChuJing = function (pushType, content, context) {
    //	_self.pushDialog(content.messageTypeIcon,content.messageTypeName,content.description,["查看详情","取消"],function(dialog, index){
    //if(index != 1){
    _self.setRead(content, context);
    _self.jumpPageIsCurrentPage("policeHistoryDetail", "/policeHistoryDetail/" + context.fcFacilitiesId + "/" + context.businessId + "/" + context.createTime + "/");
    //}
    //});
  }

  //高位信号
  _self.dealPushForGaoWeiXinHao = function (pushType, content, context) {
    // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
    // 	if (index != 1) {
    _self.setRead(content, context);
    _self.jumpPageIsCurrentPage("fireHazardDetail", "/fireHazardDetail/" + context.businessId + "/0/");
    // 	}
    // });
  }

  //重大问题
  _self.dealPushForZhongdaWenTi = function (pushType, content, context) {
    // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
    // 	if (index != 1) {
    _self.setRead(content, context);
    _self.jumpPageIsCurrentPage("keyIssuesDetail", "/keyIssuesDetail/" + context.businessId + "/0/");
    // 	}
    // });
  }

  //查岗 单位安全管理员、单位领导、系统管理员有查岗权限
  _self.dealPushForChaGang = function (pushType, content, context) {
    //401 发起
    if (pushType == 401) {
      //获取当前定位
      // _self.pushDialog(content.messageTypeIcon,content.messageTypeName,content.description,["立即应答","取消"],function(dialog, index){
      //获取当前定位
      native.requestLocation();
      // if(index != 1){
      _self.setRead(content, context);
      //延迟应答，接收原生经纬度数据
      setTimeout(() => {
        Dao.responseTip({
          orgId: content.organizationId,
          inspectId: context.businessId,
          longitude: app.data.longitude,
          latitude: app.data.latitude,
        }, function (data) {
          if (data.status == 200) {
            app.methods.showToastCenter("应答成功");
          } else {
            app.methods.showToastCenter(data.info);
          }
        });
      }, 1000);
      // 	}
      // });
    }
    //提前全部应答
    else if (pushType == 402) {
      // _self.pushDialog(content.messageTypeIcon,content.messageTypeName,content.description,["查看详情","取消"],function(dialog, index){
      // 	if(index != 1){
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("inspectionApplyRecords", "/inspectionApplyRecords/" + context.businessId + "/");
      // 	}
      // })
    }
    //查岗到期
    else if (pushType == 403) {
      // _self.pushDialog(content.messageTypeIcon,content.messageTypeName,content.description,["查看详情","取消"],function(dialog, index){
      // 	if(index != 1){
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("inspectionApplyRecords", "/inspectionApplyRecords/" + context.businessId + "/");
      // 	}
      // })
    }
  }

  //打卡
  _self.dealPushForDaKa = function (pushType, content, context) {
    // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["立即打卡", "取消"], function (dialog, index) {
    // 	if (index != 1) {
    _self.setRead(content, context);
    _self.jumpPageIsCurrentPage("clockIn", "/clockIn/");
    // 	}
    // })
  }

  //签到 --对应的签到记录页
  _self.dealPushForQianDao = function (pushType, content, context) {
    // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
    // 	if (index != 1) {
    _self.setRead(content, context);
    _self.jumpPageIsCurrentPage("signInRecord", "/signInRecord/" + context.userAccount + "/");
    // 	}
    // })
  }

  //巡检
  _self.dealPushForXunJian = function (pushType, content, context) {
    let vueWindow = document.getElementById('vueIframe').contentWindow
    let myVue = vueWindow.myVue
    if (pushType == 701) {
      // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      // 	if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("checkApply", "/checkApply/0/0/0/0/", () => {
        if (myVue.$route.name != 'InspectMain') {
          myVue.$router.push({
            name: 'InspectMain',
            query: {
              refresh: 1
            }
          })
        } else {
          vueWindow.setInspectTab(0)
        }
      });
      // 	}
      // })
    }
    //已完成、执行中
    else {
      // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      // 	if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("checkApply", `/checkApply/InspectDetail/${context.businessId}/${pushType == 704 ? 0 : 1}/0/`, () => {
        if (myVue.$route.name != 'InspectDetail') {
          myVue.$router.push({
            name: 'InspectDetail',
            query: {
              item: context.businessId,
              readonly: pushType == 704 ? '' : 1
            },
            params: { refresh: true }
          })
        } else {
          myVue.$store.commit('setCurInspectTaskId', context.businessId)
        }
      });
      // app.accordion.open("#checkApply_acc_" + context.businessId);
      // 	}
      // })
    }
  }

  //隐患整改
  _self.dealPushForYinHuanZhengGai = function (pushType, content, context) {
    //指派
    if (pushType == 801 || pushType == 809) {
      // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      // 	if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("goAppoint", "/goAppoint/" + context.businessId + "/");
      // 	}
      // })
    }
    //整改
    else if (
      pushType == 802 || pushType == 803 || pushType == 804 || pushType == 806 || pushType == 808 ||
      pushType == 810 || pushType == 811 || pushType == 812 || pushType == 814 || pushType == 816
    ) {
      // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      // 	if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("goRectification", "/goRectification/" + context.businessId + "/");
      // 	}
      // })
    }
    //核实
    else if (pushType == 805 || pushType == 813) {
      // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      // 	if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("goVerify", "/goVerify/" + context.businessId + "/");
      // 	}
      // })
    }
    //完成807
    else {
      // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      // 	if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("finishMsg", "/finishMsg/" + context.businessId + "/");
      // 	}
      // })
    }
  }

  //维保巡查
  _self.dealPushForWeiBaoXUnCha = function (pushType, content, context) {
    //未开始
    if (pushType == 901 || pushType == 902) {
      // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      // 	if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("maintainInspect", "/maintainInspect/0/");
      // 	}
      // })
    } else if (pushType == 904 || pushType == 905 || pushType == 907 || pushType == 908) {
      // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      // 	if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("maintainInspectDetail", "/maintainInspectDetail/" + context.businessId + "/0/");
      // 	}
      // })
    }
  }

  //保养
  _self.dealPushForBaoYang = function (pushType, content, context) {
    //未开始
    if (pushType == 1001 || pushType == 1002) {
      // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      // 	if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("maintain", "/maintain/0/");
      // 	}
      // })
    } else if (pushType == 1004 || pushType == 1005 || pushType == 1007 || pushType == 1008 || pushType == 1009) {
      // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      // 	if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("maintainDetail", "/maintainDetail/" + context.businessId + "/0/");
      // 	}
      // })
    }
  }
  //考试
  _self.dealPushForKaoShi = function (pushType, content, context) {
    // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
    // if(pushType==9907){
    // 	if (index != 1) {
    _self.setRead(content, context);
    _self.jumpPageIsCurrentPage("exam", "/exam/");
    // 	}
    // }
    // 	}	)
  },
    //警情关闭
    _self.dealPushForPoliceClose = function (pushType, content, context) {
      //_self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      // if(pushType==1701||pushType==1702){
      // 	if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("closeReminder", "/closeReminder/");
      // 	}
      // }
      // 	}	)
    },
    //现场交接
    _self.dealPushForChangeShift = function (pushType, content, context) {
      if (pushType == 10001) {
        if (app.view.current.el.f7View.router.currentPageEl.f7Component.pageName == 'changeShifts' && context.dutyAccounts.indexOf(userInfor.accountName) > -1) {
          shiftStatus = true;
          changeShiftsType = context.type
          changeShiftsId = context.businessId

          if (jQuery('#qrcode').length > 0 && window.QRid == changeShiftsId) {
            app.view.current.router.currentPageEl.f7Component.pushCode()
            app.view.current.router.currentPageEl.f7Component.getHistoryPoliceList()

          }
          //_self.jumpPageIsCurrentPage("changeShifts", `/changeShifts/${context.businessId}/${context.type}/`);
        }
        if (app.view.current.el.f7View.router.currentPageEl.f7Component.pageName == 'changeShiftsDetails' && context.dutyAccounts.indexOf(userInfor.accountName) > -1) {
          shiftStatus = true;
          changeShiftsId = context.businessId
          changeShiftsType = context.type

          if (jQuery('#qrcode').length > 0 && window.QRid == changeShiftsId) {
            app.view.current.router.currentPageEl.f7Component.shiftsFun()
            app.view.current.router.currentPageEl.f7Component.getData()
          }

          //	_self.jumpPageIsCurrentPage("changeShiftsDetails", `/changeShiftsDetails/${context.businessId}/${context.type}/`);
        }
      }
    },

    //单点测试
    _self.dealPushForDanDianCeShi = function (pushType, content, context) {
      //未开始
      if (pushType == 1101) {
        //_self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
        if (index != 1) {
          _self.setRead(content, context);
          _self.jumpPageIsCurrentPage("singleTest", "/singleTest/0/");
        }
        //})
      }
      //进行中
      else if (pushType == 1102) {
        //_self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
        if (index != 1) {
          _self.setRead(content, context);
          _self.jumpPageIsCurrentPage("singleTest", "/singleTest/1/");
        }
        //})
      } else if (pushType == 1104 || pushType == 1105 || pushType == 1107) {
        //_self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
        if (index != 1) {
          _self.setRead(content, context);
          _self.jumpPageIsCurrentPage("singleTestDetail", "/singleTestDetail/" + context.businessId + "/0/");
        }
        //})
      }
    }

  //联动测试
  _self.dealPushForLianDongCeShi = function (pushType, content, context) {
    //未开始
    if (pushType == 1201 || pushType == 1202) {
      //_self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      if (index != 1) {
        _self.setRead(content, context);
        _self.jumpPageIsCurrentPage("linkTest", "/linkTest/0/");
      }
      //})
    }
    //进行中
    else if (pushType == 1203) {
      //_self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      if (index != 1) {
        _self.setRead(content, context);
        _self.jumpPageIsCurrentPage("linkTest", "/linkTest/1/");
      }
      //})
    } else if (pushType == 1204 || pushType == 1205 || pushType == 1207 || pushType == 1208) {
      //_self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      if (index != 1) {
        _self.setRead(content, context);
        _self.jumpPageIsCurrentPage("linkTestDetail", "/linkTestDetail/" + context.businessId + "/");
      }
      //})
    }
  }

  //测试
  //maintainType 1 维保巡查任务 2保养任务 3测试任务 4联动测试任务
  //{"context":"{\"organizationId\":156,\"businessId\":3403,\"accounts\":\"x1\",\"maintainType\":4,\"organizationIdName\":\"山海酒店\",\"accountNames\":\"许一\",\"pushType\":1}","createTime":"2019-07-30 16:03:21","description":"山海酒店正在由许一等进行测试，测试期间可能会引发警情，请谨慎","isUnit":0,"messageType":1301,"organizationId":156,"roleIds":"142,144,145,160,184,185"}
  _self.dealPushForCeShi = function (pushType, content, context) {
    custom.getTestTask();
    custom.showTaskList();
    custom.refreshTaskList();
    // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
    // 	if (index != 1) {
    _self.setRead(content, context);
    if (context.maintainType == 1) {
      _self.jumpPageIsCurrentPage("maintainInspectDetail", "/maintainInspectDetail/" + context.businessId + "/0/");
    } else if (context.maintainType == 2) {
      _self.jumpPageIsCurrentPage("maintainDetail", "/maintainDetail/" + context.businessId + "/0/");
    } else if (context.maintainType == 3) {
      _self.jumpPageIsCurrentPage("singleTestDetail", "/singleTestDetail/" + context.businessId + "/0/");
    } else if (context.maintainType == 4) {
      _self.jumpPageIsCurrentPage("linkTestDetail", "/linkTestDetail/" + context.businessId + "/");
    }
    // 	}
    // })
  }

  //临时任务
  _self.dealPushForLinShiRenWu = function (pushType, content, context) {
    // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
    // 	if (index != 1) {
    _self.setRead(content, context);
    _self.jumpPageIsCurrentPage("temporaryTaskDetail", "/temporaryTaskDetail/" + context.businessId + "/");
    // 	}
    // })
  }

  //作业申请
  _self.dealPushForZuoYeShenQing = function (pushType, content, context) {
    // _self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
    // 	if (index != 1) {
    _self.setRead(content, context);
    _self.jumpPageIsCurrentPage("workApplyDetail", "/workApplyDetail/" + context.businessId + "/0/");
    // 	}
    // })
  }

  //应急救援
  _self.dealPushForYingJiJiuYuan = function (pushType, content, context) {
    if (pushType == 1601) {
      //	_self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      //if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("dealEmergencyApply", "/dealEmergencyApply/");
      //}
      //	})
    } else {
      //_self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      //if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("emergencyDetail", '/emergencyDetail/' + context.planId + '/' + context.businessId + '/');
      //}
      //})
    }
  }

  //其他推送
  _self.dealPushForOther = function (pushType, content, context) {
    //维保报告
    if (pushType == 9903) {
      //_self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      //if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("maintenceReport", "/maintenceReport/" + context.businessId + "/");
      //}
      //})
    }
    //消防报表
    else if (pushType == 9901) {
      //_self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      //if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("reportApplyDetail", "/reportApplyDetail/" + context.businessId + "/" + context.isUnit + "/" + context.name + `/1/${context.period}/`);
      //}
      //})
    }
    //九小公告
    else if (pushType == 9904) {
      //_self.pushDialog(content.messageTypeIcon, content.messageTypeName, content.description, ["查看详情", "取消"], function (dialog, index) {
      //if (index != 1) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("ninePlaceDetail", "/ninePlaceDetail/" + context.businessId + "/");
      //}
      //})
    }
    //年报
    else if (pushType == 9908) {
      _self.setRead(content, context);
      _self.jumpPageIsCurrentPage("yearReport", "/yearReport/" + context.businessId + "/");
    }
  }
  //判断当前用户是否已登录
  _self.isLoadSys = function () {
    if (userInfor && userLoggedIn) {
      return true;
    } else {
      return false;
    }
  }
  //推送提示
  _self.pushDialog = function (icon, tittle, des, btns, call) {
    let iconTittle = "推送提示";
    if (tittle) {
      iconTittle = icon ? ("<img src=" + icon + " style='width:26px;height:26px;margin-right:8px;float: left;' />" + tittle) : tittle
    }
    //按鈕集合
    let btnArr = [{
      text: "关闭",
    }];
    if (btns && btns.length > 0) {
      btnArr = [];
      for (let i = 0; i < btns.length; i++) {
        if (btns[i]) {
          btnArr.push({
            text: btns[i],
          })
        }
      }
    }
    app.dialog.create({
      title: iconTittle,
      text: des ? des : "未知消息",
      buttons: btnArr,
      verticalButtons: false,
      onClick: function (dialog, index) {
        if (call) {
          call(dialog, index);
        }
      },
    }).open();
  }

  //判断接收到推送消息的时候是不是当前页
  _self.jumpPageIsCurrentPage = function (router, url, customNavigate) {
    var history = app.view.current.history[app.view.current.history.length - 1];
    history = history.replace('/', '');
    history = history.substr(0, history.indexOf('/'));
    if (isFromMessage === 1 || history === router) {
      if (router === 'checkApply' && history === 'checkApply') { //巡检
        customNavigate()
      } else if (app.view.current.el.f7View.router.currentPageEl.f7Component.pageName == 'changeShifts') {
        app.view.current.router.back(url, {
          force: true
        })
      } else if (app.view.current.el.f7View.router.currentPageEl.f7Component.pageName == 'changeShiftsDetails') {
        app.router.navigate(url, {
          reloadCurrent: true
        });
        // app.view.current.router.back(url,{force:true})
      } else {
        app.router.navigate(url, {
          reloadCurrent: true
        });
      }
    } else {
      if (router === 'checkApply' && history === 'checkApply') { //巡检
        customNavigate()
      } else {
        isFromMessage = 1;
        pushMessageurl = url;
        app.router.navigate(url);
      }
    }
  }


  return _self;
})(window.push || {});